
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><?php echo $title;?></title>
    <!-- 设置缩放 -->
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
    <meta name="format-detection" content="telephone=no" />
    <!-- windows phone 点击无高光 -->
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- icon -->
    <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />

    <style>
        .search_box{padding:10px 0 10px 0;}
        .search_box input,.search_box select{width:200px;height:25px;border:1px solid #ddd;padding:0 10px;margin-bottom: 10px;}
        .search_box select{width:100px;height:27px;}
        .search_box select#search_group{width:130px;}
        .search_box .datetime{width:80px;}
        #search_btn, #download_execlbtn, .add_essay_btn{margin-right:20px;}
        #search_group{width:100px;}
    </style>
</head>
<?php
$userLevel = getUserLevel();
$mouldCode = isset($mouldCode) ? $mouldCode : '-';
$searchInfo = isset($searchInfo) ? $searchInfo : array();
$ListUrl1 = SYS_URL_PATH("admin_power_funs");
$ListUrl2 = SYS_URL_PATH("admin_power_index");
$seqUrl = SYS_URL_PATH("admin_power_seq/m/$mouldCode");
$addUrl = SYS_URL_PATH("admin_power_addfuns/m/$mouldCode");
?>
<body>
<div class="con_box">
    <div class="lab_box2" style="width:1400px">
        <a href="<?php echo $ListUrl1;?>" class="lab_base2 act">功能列表<span class="lab_act2"></span></a>
        <a href="<?php echo $ListUrl2;?>" class="lab_base2 " >角色列表</a>
    </div>
    <?php
    $search_title = isset($searchInfo['locate']['a.title']) ? $searchInfo['locate']['a.title'] : '';
    $search_status = isset($searchInfo['where']['a.status']) ? $searchInfo['where']['a.status'] : '';
    $search_startdate = isset($searchInfo['gts']['a.createdate']) ? $searchInfo['gts']['a.createdate'] : '';
    $search_enddate = isset($searchInfo['lts']['a.createdate']) ? $searchInfo['lts']['a.createdate'] : '';
    $search_group = isset($searchInfo['where']['a.menu_id']) ? $searchInfo['where']['a.menu_id'] : '';
    ?>
    <div class="search_box">
        <input type="text" id="search_word" value="<?php echo $search_title;?>" placeholder="请输入角色关键词">
        <select id="search_group">
            <option value="">请选择菜单/类</option>
        <?php
        if(isset($classlist)) {
            foreach ($classlist as $v) {
                $level = $v['level']*2;
                $str = str_pad("",$level, '-',STR_PAD_LEFT );
                $fontb = $v['fid'] == 0 ? 'fontb' : '';
                $act = $search_group == $v["id"] ? 'act' : '';
                $selected = $search_group == $v["id"] ? 'selected="selected"' : '';
                echo '<option value="' . $v["id"] . '" class="'.$fontb.' '.$act.'" '.$selected.'>' .$str .' '. $v["menuname"] . '</option>';
            }
        }
        if(isset($classlistFuns)){
            foreach($classlistFuns as $k=>$v){
                $act = $search_group == $k ? 'act' : '';
                $selected = $search_group == $k ? 'selected="selected"' : '';
                echo '<option value="' . $k . '" class="'.$fontb.' '.$act.'" '.$selected.'>' .$v . '</option>';

            }
        }
        ?>
        </select>
        <select id="search_status">
            <option value="">请选状态</option>
            <?php
            if(isset($statusList) && !empty($statusList)){
                foreach($statusList as $k=>$v){
                    $search_status_de = $search_status == $k ? 'selected="selected"' : '';
                    echo '<option value="'.$k.'" '.$search_status_de.'>'.$v.'</option>';
                }
            }
            ?>
        </select>
        <input type="text" id="date_start" class="datetime" value="<?php echo $search_startdate;?>" placeholder="起始日期">
        ~
        <input type="text" id="date_end" class="datetime" value="<?php echo $search_enddate;?>" placeholder="终止日期">
        &nbsp; &nbsp;
        <button class="btn_base btn_back_sides btn_height25" id="search_btn">搜索</button>
        <button class="btn_base btn_back_greens2 btn_height25" id="download_execlbtn">导出</button>
        <button class="btn_base btn_back_oranges btn_height25 add_essay_btn" data-url="<?php echo $addUrl;?>">添加</button>
    </div>
    <table class="table_th_td" id="table_list" style="width:1400px">
        <tr class="weight400">
            <th width="42"><input type="checkbox" class="checkbox_all"></th>
            <th width="50">排序</th>
            <th width="50">ID</th>
            <th>功能</th>
            <th width="120">菜单名/类昵称</th>
            <th width="120">菜单ID/类名</th>
            <th width="90">方法</th>
            <th width="80">类型</th>
            <th width="80">展示</th>
            <th width="120">状态</th>
            <th width="150">时间</th>
            <th width="120">操作</th>
        </tr>
        <?php
        if(isset($list) && !empty($list)){
            foreach($list as $k=>$v){
                $id = $v['id'];
                $title = $v['title'];
                $funcode = $v['funcode'];
                $menu_id = $v['menu_id'];
                $menuname = $v['menuname'];
                $types = $v['types'] == 1 ? '菜单' : ($v['types'] == 2  ? '文章' : '其他');
                $flag = $v['flag'] == 1 ? '开发者' : '管理员';
                $viewseq = $v['viewseq'];
                $statustxt = $v['statustxt'];
                $createdate = $v['createdate'];
                $updateUrl = SYS_URL_PATH("admin_power_updatefuns/m/$mouldCode/i/$id");
                $delUrl = SYS_URL_PATH("admin_power_delfuns/m/$mouldCode/i/$id");
                echo <<<html
                    <tr>
                        <td class="center"><input type="checkbox" class="checkbox_no" name="id[]" value="$id"></td>
                        <td class="center"><input type="text" class="viewseq" data-id="$id" value="$viewseq"></td>
                        <td class="center">$id</td>			
                        <td class="center">$title</td>
                        <td class="center">$menuname</td>
                         <td class="center">$menu_id</td>
                        <td class="center">$funcode</td>
                        <td class="center">$types</td>
                        <td class="center">$flag</td>
                        <td class="center">$statustxt</td>
                        <td class="center">$createdate</td>
                        <td class="center">
                            <a href="javascript:;" data-url="$updateUrl" class="btn_base btn_line_none essay_update_btn" >编辑</a>
                            <a href="javascript:;" data-url="$delUrl" class="btn_base btn_line_none essay_del_btn" >删除</a>
                        </td>
                    </tr>
html;
            }
        }
        ?>
        <tr class="operates_box">
            <td class="center">
                <button class="btn_base btn_height20 btn_line_none" id="delall_btn" title="批量删除">Del</button>
            </td>
            <td class="center">
                <button class="btn_base btn_height20 btn_line_none" id="viewseq_btn" data-url="<?php echo $seqUrl;?>" title="提交排序">↓↑</button>
            </td>
            <td class="center">
                <!-- 选中的下载Execl -->
                <button class="btn_base btn_height20 btn_line_none btn_lineheight25" id="down_execl_btn" title="下载Execl"></button>
            </td>
            <td class="center" colspan="6"></td>
            <td class="center">
                <?php
                // 选中的批量修改状态
                echo '<select class="select selectw50" id="newStatus">';
                echo '<option value="1">待审</option>';
                echo '<option value="2">已审</option>';
                echo '<option value="3">关闭</option>';
                echo '</select>'.PHP_EOL;
                echo '<button class="btn_base btn_height20" id="status_btn" title="批量修改">操作</button>';
                ?>
            </td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <?php
    $pageNo = isset($pages["pageNo"]) ? intval($pages["pageNo"]) : 1;
    $pageSum = isset($pages["pageSum"]) ? intval($pages["pageSum"]) : 1;
    $counts = isset($pages["counts"]) ? intval($pages["counts"]) : 0;
    ?>
    <div class="page_box">
        <i class="page_start">首页</i>
        <i class="page_prev">上一页</i>
        <input type="number" class="page_no" value="<?php echo $pageNo;?>"> /
        <span class="page_sum"><?php echo $pageSum;?></span>
        <i class="page_next">下一页</i>
        <i class="page_end">尾页</i>
        <span class="page_list">共 <b><?php echo $counts;?> </b>条记录</span>
    </div>
</div>
</body>
<script language="javascript">
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
    var pageNo = '<?php echo $pageNo;?>';
    var pageSum = '<?php echo $pageSum;?>';
    var essayUrl = '<?php echo "admin_power_funs";?>';
    var downExeclUrl = '<?php echo SYS_URL_PATH("admin_power_execl/m/$mouldCode");?>';
    var delMoreUrl = '<?php echo SYS_URL_PATH("c_common_dels/m/$mouldCode");?>';
    var statusUrl = '<?php echo SYS_URL_PATH("c_common_status/m/$mouldCode");?>';
</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('list');</script>
<script language="javascript">
    var nowDate = '<?php echo date("Y-m-d");?>';
    // 加载完毕后
    window.onload = function () {

        // 日期
        jeDate({
            dateCell: '#date_start',
            isTime: false,
            format: 'YYYY-MM-DD',
            minDate: '2022-06-01',
            maxDate:nowDate
        })

        // 日期
        jeDate({
            dateCell: '#date_end',
            isTime: false,
            format: 'YYYY-MM-DD',
            minDate: '2022-06-01',
            maxDate:nowDate
        })
    }

    // 获取ckeckbox选中的值
    function getCheckedVal(){
        let chk_value =[];
        $('.checkbox_no:checked').each(function(){
            chk_value.push($(this).val());
        });
        var selectId = chk_value.join(",");
        console.log(selectId);
        return selectId;

    }

    // 全选
    $('.checkbox_all').click(function(){
        let checkboxFlag = $('.checkbox_all').prop('checked');
        if(checkboxFlag){
            $('.checkbox_no').attr('checked','checked');
            getCheckedVal();
        }else{
            $('.checkbox_no').removeAttr('checked');
        }
    })

    ////////////////////////////////////////////

    //添加/修改文章
    $('.add_essay_btn,.essay_update_btn').click(function(){
        layerIframeOpen($(this).attr('data-url'),  '600px', '500px', 1);
    });

    var flagSub = true;

    //删除
    $('.essay_del_btn').click(function(){
        let goutoURL = $(this).attr('data-url');
        if(!goutoURL){
            layer.msg('网络异常');
        }else{
            layer.confirm('确定删除？', {
                btn: ['确定','取消']
            }, function(){
                if(!flagSub){
                    layer.msg('处理中……(禁止重复提交)');return false;
                }
                flagSub = false;
                $.post(goutoURL, {subFlag:'Y'}, function(data){
                    flagSub = true;
                    if(data=='Y'){
                        layer.msg('删除成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        flagSub = true;
                        layer.msg('操作失败_'+data);
                    }
                },'json');
            }, function(){ });
        }
    })

    // 批量删除
    $('#delall_btn').click(function(){
        let idStr = getCheckedVal();
        if(!idStr){
            layer.msg('请先选中');
        }else{
            layer.confirm('确定删除选中的？', {
                btn: ['确定','取消']
            }, function(){
                if(!flagSub){
                    layer.msg('处理中……(禁止重复提交)');return false;
                }
                flagSub = false;
                $.post(delMoreUrl, {i:idStr,}, function(data){
                    flagSub = true;
                    if(data=='Y'){
                        layer.msg('删除成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json').error(function(){
                    flagSub = true;
                    layer.msg('网络异常');
                });
            }, function(){ });
        }
    });

    // 批量下载
    $('#down_execl_btn').click(function(){
        let idStr = getCheckedVal();
        if(!idStr){
            layer.msg('请先选中');
        }else{
            var confirmlayer = layer.confirm('确定导出选中的数据？', {
                btn: ['确定','取消']
            }, function(){
                flagSub = false;
                layer.close(confirmlayer);// 关闭加载层
                jspost(downExeclUrl, {i:idStr});
            }, function(){ });
        }
    });

    // 批量修改状态
    $('#status_btn').click(function(){
        let idStr = getCheckedVal();
        let newStatus = $('#newStatus').val();
        if(!idStr || !newStatus){
            layer.msg('请先选中');
        }else{
            layer.confirm('确定修改选中的？', {
                btn: ['确定','取消']
            }, function(){
                if(!flagSub){
                    layer.msg('处理中……(禁止重复提交)');return false;
                }
                flagSub = false;
                $.post(statusUrl, {i:idStr,s:newStatus}, function(data){
                    flagSub = true;
                    if(data=='Y'){
                        layer.msg('操作成功');
                        setTimeout(function(){
                            window.location.reload();
                        },2500);
                    }else{
                        layer.msg('操作失败_'+data);
                    }
                },'json').error(function(){
                    layer.msg('网络异常');
                    flagSub = true;
                });
            }, function(){ });
        }
    });

    // 筛选条件
    function listGoTo(listUrl){
        let search = {};
        search.search_title = $('#search_word').val();
        search.search_status = $('#search_status').val();
        search.search_startdate = $('#date_start').val();
        search.search_enddate = $('#date_end').val();
        search.search_group = $('#search_group').val();
        let dataJson = JSON.stringify(search);
        jspost(http_url+listUrl+http_fix, {search:dataJson});
    }

    //分页-首页
    $('.page_start').click(function(){
        let listUrl = essayUrl+'/p/1';
        listGoTo(listUrl);
    });

    //分页-尾页
    $('.page_end').click(function(){
        let listUrl = essayUrl+'/p/'+pageSum;
        listGoTo(listUrl);
    });

    //分页-上一页
    $('.page_prev').click(function(){
        let prevPage = parseInt(pageNo)-1 > 1 ? parseInt(parseInt(pageNo)-1) : 1;
        let listUrl = essayUrl+'/p/'+prevPage;
        listGoTo(listUrl);
    });

    //分页-下一页
    $('.page_next').click(function(){
        let nextPage = parseInt(parseInt(pageNo)+1) > pageSum ? pageSum : parseInt(parseInt(pageNo)+1);
        let listUrl = essayUrl+'/p/'+nextPage;
        listGoTo(listUrl);
    });

    //分页-跳页
    $('.page_no').blur(function(){
        let page_no = $('.page_no').val();
        let listUrl = essayUrl+'/p/'+page_no;
        listGoTo(listUrl);
    });

    // 导出execl
    $('#download_execlbtn').click(function(){
        window.location.href = downExeclUrl;
    });

    // 查询
    $('#search_btn').click(function(){
        listGoTo(essayUrl);
    });


</script>
</html>